#include <iostream>
#include <memory>

typedef struct item_s {
    int val;
} item_t;

item_t *item_new(int v) {
    item_t *c_item = (item_t *)malloc(sizeof(item_t));
    c_item->val = v;

    std::cout << "[ item_new ] item: " << c_item << std::endl;

    return c_item;
}

void item_free(item_t *c_item) {
    if (c_item)
        free(c_item);

    c_item = NULL;

    std::cout << "[ item_free ] destroyed. " << std::endl;
}

int main() {
    std::cout << "[ main ] pre new item... " << std::endl;
    item_t *item = item_new(10);
    std::cout << "[ main ] after new item... " << std::endl;

    std::shared_ptr<item_t> p(item, item_free);
    std::cout << "[ main ] after new shared ptr... " << std::endl;

    p = nullptr;
    std::cout << "[ main ] after shared ptr to null... " << std::endl;

    //item_free(item);
    std::cout << "[ main ] finished. " << std::endl;

    return 0;
}
